import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2022-09-05
 * Time: 22:20
 */
public class Solution2 {
    public static void rotate(int[] nums, int k) {
        k %= nums.length;
        revers(nums, 0, nums.length-1);
        revers(nums, 0, k-1);
        revers(nums, k, nums.length-1);
    }
    public static void revers(int[] nums, int from, int to) {
        while (from < to) {
            int tmp = nums[from];
            nums[from] = nums[to];
            nums[to] = tmp;
            from++;
            to--;
        }
    }


    public static void main(String[] args) {
        int[] arr = {1,2,3,4};
        rotate(arr, 2);
        System.out.println(Arrays.toString(arr));
    }
}
